//
//  UIView+Progress.m
//  FrameTest
//
//  Created by Tiger on 11-10-22.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "UIView+Progress.h"
#import <QuartzCore/QuartzCore.h>
#import <unistd.h>

#define PROGRESS_FOR_UIVIEW_TAG 99901

@implementation UIView(Progress)


- (void)showWhiteProgress:(BOOL)show
{
	if (show) {
		UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
											 UIActivityIndicatorViewStyleWhite];
		[progress startAnimating];
		progress.center = self.center;
		progress.tag = PROGRESS_FOR_UIVIEW_TAG;
		[self addSubview: progress];
		[progress release];
	}
	else {
		UIView *progressView = [self viewWithTag: PROGRESS_FOR_UIVIEW_TAG];
		[progressView removeFromSuperview];
		progressView = nil;
	}
}

- (void)showGrayProgress:(BOOL)show
{
	if (show) {
		UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
											 UIActivityIndicatorViewStyleGray];
		[progress startAnimating];
		progress.center = self.center;
		progress.tag = PROGRESS_FOR_UIVIEW_TAG;
		[self addSubview: progress];
		[progress release];
	}
	else {
		UIView *progressView = [self viewWithTag: PROGRESS_FOR_UIVIEW_TAG];
		[progressView removeFromSuperview];
		progressView = nil;
	}
}

- (void)showProgressText:(BOOL)show
{
	if(show) {
		
		UIView *progressView = [[UIView alloc] initWithFrame:CGRectMake(120,150,80,80)];
		progressView.backgroundColor = [UIColor blackColor];
		progressView.layer.cornerRadius = 10;
		progressView.alpha = 0.7f;
		//progressView.center = self.center;
		progressView.tag = PROGRESS_FOR_UIVIEW_TAG;
		[self addSubview: progressView];
        [progressView release];
		
        UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
											 UIActivityIndicatorViewStyleWhiteLarge];
        progress.frame = CGRectMake(25, 20, 30, 30);
        //progress.center = progressView.center;
        [progressView addSubview: progress];
        [progress release];
        [progress startAnimating];
        
		UILabel *loadText = [[UILabel alloc]initWithFrame: CGRectMake(0, 55, 80, 20)];
		loadText.backgroundColor =[UIColor clearColor];
		loadText.font = [UIFont systemFontOfSize: 12];
		loadText.textAlignment = UITextAlignmentCenter;
		loadText.textColor = [UIColor whiteColor];
		loadText.text = LS(@"正在加载...");
		[progressView addSubview: loadText];
		
		[loadText release];
	} else {
		UIView *progressView = [self viewWithTag: PROGRESS_FOR_UIVIEW_TAG];
		[progressView removeFromSuperview];
		progressView = nil;
	}
}

- (void)drawShadow {
	self.layer.cornerRadius =2.0;
	self.layer.shadowOffset = CGSizeMake(2, 2);
	self.layer.shadowRadius = 1.0;
	self.layer.shadowColor = [UIColor blackColor].CGColor;
	self.layer.shadowOpacity = 0.8;
	self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
}
- (void)showAlert:(NSString*)title message:(NSString*)message{
    UIAlertView* al=[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:LS(@"确定") otherButtonTitles:nil];
    [al show];
    [al release];
}
@end
